package com.refusea.train.controller

import com.refusea.train.domain.entity.Referrer
import com.refusea.train.domain.helper.ReferrerHelper
import com.refusea.train.domain.req.ReferrerCommissionReq
import com.refusea.train.domain.vo.CommissionStatVo
import com.refusea.train.domain.vo.PaginationVo
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.time.LocalDate

/**
 * @author Zhang Yan 2024/4/23
 **/
@RestController
@RequestMapping("/api/private/referrer/")
class ReferrerController(private val referrerHelper: ReferrerHelper) {


    @GetMapping("/list")
    fun list(): List<Referrer> {
        return referrerHelper.list()
    }

    @GetMapping("/delete")
    fun delete(id: Int) {
        return referrerHelper.delete(id)
    }

    @PostMapping("/save")
    fun save(@RequestBody referrer: Referrer) {
        referrerHelper.save(referrer)
    }

    @PostMapping("/commissions")
    fun commissions(@RequestBody req: ReferrerCommissionReq): PaginationVo {
        return referrerHelper.commissions(req)
    }

    @GetMapping("/pay")
    fun pay(id: Int, date: LocalDate) {
        return referrerHelper.pay(id, date)
    }

    @GetMapping("/stat")
    fun stat(): CommissionStatVo {
        return referrerHelper.stat()
    }
}
